//接口是一种引用类型
//  1.使用interface方法修饰
//  2.不能有被实现的方法，只能能有抽象方法，除static修饰和default
//  3.接口方法默认是public abstract修饰
//  4.接口成员变量默认是public static final修饰
//  5.接口不能实例化，即不能有构造和实例代码块
//  6.类和接口使用implements
//  7.接口与接口继承使用extends
//  8.一般以I开头
//

import java.util.Comparator;

import static java.lang.System.out;

abstract class Animal
{
    private String name;
    private int age;

    public Animal(String name, int age) {
        this.name = name;
        this.age = age;
    }

    public String getName() {
        return name;
    }

    public int getAge() {
        return age;
    }

    public abstract void eat();
}

interface IFly
{
    void fly();
}

interface IRun
{
    void run();
}

interface ISwim
{
    void swim();
}

class Dog extends Animal implements IRun
{
    public Dog(String name, int age) {
        super(name, age);
    }

    @Override
    public void run() {
        out.println(super.getName() + "用四条腿跑");
    }

    @Override
    public void eat() {
        out.println(super.getName() + "在吃狗粮");
    }
}

class Frog extends Animal implements IRun,ISwim
{
    public Frog(String name, int age) {
        super(name, age);
    }

    @Override
    public void eat() {
        out.println(super.getName() + "在吃蛙粮");
    }

    @Override
    public void run() {
        out.println(super.getName() + "在用两条腿跳着跑");
    }

    @Override
    public void swim() {
        out.println(super.getName() + "在蛙泳");
    }
}

class Duck extends Animal implements IRun,IFly,ISwim {
    public Duck(String name, int age) {
        super(name, age);
    }

    @Override
    public void eat() {
        out.println(super.getName() + "在吃鸭粮");
    }

    @Override
    public void run() {
        out.println(super.getName() + "在用两条腿一扭一扭的跑");
    }

    @Override
    public void swim() {
        out.println(super.getName() + "在鸭泳");
    }

    @Override
    public void fly() {
        out.println(super.getName() + "在鸭飞");
    }
}

interface A
{
    void testA();
}

interface B extends A
{
    void B();
}

class testDemo1 implements B
{
    @Override
    public void testA() {

    }

    @Override
    public void B() {

    }
}



//比较器
//  1.Comparable 接口 重写 compareTo(o)方法，写死不容易更改一般用于默认比较方法
//  2.Compartor 接口 重写 compare(o1, o2)方法，灵活
//
class Cat extends Animal implements Comparable<Cat>
{
    public Cat(String name, int age) {
        super(name, age);
    }

    @Override
    public void eat() {
        out.println(super.getName() + "在吃猫粮");
    }

    @Override
    public int compareTo(Cat o) {
        return this.getAge() - o.getAge();
    }
}

class CatNameCompara implements Comparator<Cat>
{
    @Override
    public int compare(Cat o1, Cat o2) {
        return o1.getName().compareTo(o2.getName());
    }
}

public class Interface {
    public static void running(IRun r)
    {
        r.run();
    }
    public static void flying(IFly f)
    {
        f.fly();
    }

    public static void swimming(ISwim s)
    {
        s.swim();
    }

    public static void main(String[] args) {
        running(new Dog("高飞",18));

        Cat cat1 = new Cat("baa", 18);
        Cat cat2 = new Cat("aa",20);

        out.println(cat1.compareTo(cat2));
        CatNameCompara nameCompara = new CatNameCompara();
        out.println(nameCompara.compare(cat1,cat2));
    }
}
